<?php
namespace App\Http\Controllers\Work;

use App\Http\Controllers\Controller;
use App\Common\Utils\JsonResponse;
use Illuminate\Http\Request;

class InWorkController extends Controller{

    private $Request;
    private $inWorkService;
    private $logService;

    public function __construct(Request $Request)
    {
        parent::__construct();

        /** @var \App\Services\Work\InWorkService $inWorkService */
        $this->inWorkService = app('inWorkService');
        $this->Request = $Request;
        /** @var \App\Services\System\LogService $logService */
        $this->logService = app('logService');
    }

     /**
     * 获取列表
     * @author lxy
     * @datetime 2023-02-28
     */
    public function getInWorkList()
    {
        try{
            $result = $this->inWorkService->getInWorkList($this->Request->all());
            return JsonResponse::success($result,'操作成功');
        }catch(\Exception $e){
            return JsonResponse::error($e->getMessage());
        }
    }

    /**
     * 添加数据
     * @author lxy
     * @datetime 2023-03-03
     */
    public function addInWork()
    {
        try{
            $result = $this->inWorkService->addInWork($this->Request->request->all());
            if(!empty($this->Request->all()['id'])){
                $this->logService->log('187','校内工作编辑', "校内工作编辑");
            }else{
                if($this->Request->all()['status'] ==1){
                    $this->logService->log('186','校内工作提交', "校内工作提交");
                }else{
                    $this->logService->log('186','校内工作保存', "校内工作保存");
                }
            }
            return JsonResponse::success($result,'操作成功');
        }catch(\Exception $e){
            return JsonResponse::error($e->getMessage());
        }
    }

    /**
     * 审核
     * @author lxy
     * @datetime 2023-03-07
     */
    public function checkInWork()
    {
        try{
            $result = $this->inWorkService->checkInWork($this->Request->all());
            if($this->Request->all()['status'] == 'PASS'){
                $this->logService->log('189','校内工作审核通过', "校内工作审核通过");
            }else{
                $this->logService->log('189','校内工作审核驳回', "校内工作审核驳回");
            }
            return JsonResponse::success($result,'操作成功');
        }catch(\Exception $e){
            return JsonResponse::error($e->getMessage());
        }
    }

    /**
     * 删除
     * @author lxy
     * @datetime 2023-03-07
     */
    public function delInWork()
    {
        try{
            $result = $this->inWorkService->delInWork($this->Request->all());
            $this->logService->log('188','校内工作删除', "校内工作删除");
            return JsonResponse::success($result,'操作成功');
        }catch(\Exception $e){
            return JsonResponse::error($e->getMessage());
        }
    }

    /**
     * 导出
     * @author lxy
     * @datetime 2023-02-24
     */
    public function exportInWork()
    {
        try{
            $result = $this->inWorkService->exportInWork($this->Request->all());
            $this->logService->log('334','校内工作导出', "校内工作导出");
            return JsonResponse::success($result,'操作成功');
        }catch(\Exception $e){
            return JsonResponse::error($e->getMessage());
        }
    }


}
